var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    select: false,
    price: ""
  },
  whether: function(e) {
    console.log(e)
    var that = this
    var button = e.detail.value
    var id = e.currentTarget.dataset.id
    var t_id = that.data.t_id
    var ff_id = that.data.ff_id
    var price = that.data.price
    var fl_id = that.data.fl_id
    if (that.data.price == "") {
      wx.showToast({
        title: '请输入实际价格',
        icon: 'none'
      })
      that.setData({
        select: false
      })
    } else {
      if (button) {
        app.util.request({
          'url': 'entry/wxapp/studio.addfwb',
          data: {
            ff_id: ff_id,
            t_id: t_id,
            price: price,
            fl_id: fl_id
          },
          success: function(res) {
            console.log(res)
            that.setData({
              id: res.data
            })
          }
        })
        wx.showToast({
          title: '开通成功',
          icon: 'none'
        })
      } else {
        app.util.request({
          'url': 'entry/wxapp/studio.delfwb',
          data: {
            id: id,
            t_id: t_id
          },
          success: function(res) {
            console.log(res)
          }
        })
        wx.showToast({
          title: '关闭成功',
          icon: 'none'
        })
      }
      that.setData({
        select: e.detail.value
      })
    }
  },
  price: function(e) {
    this.setData({
      price: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var ff_id = options.ff_id
    var t_id = options.t_id
    var fl_id = options.fl_id
    //查询是否存在一条服务包记录
    app.util.request({
      'url': 'entry/wxapp/studio.ifexist',
      data: {
        t_id: t_id,
        ff_id: ff_id,
        fl_id: fl_id
      },
      success: function(res) {
        console.log(res)
        if (res.data.data == 1) {
          that.setData({
            select: true,
            id: res.data.id,
            price: res.data.fw_sjmoney
          })
        } else {
          that.setData({
            select: false
          })
        }

      }
    })
    app.util.request({
      'url': 'entry/wxapp/Office.fwdetail',
      data: {
        ff_id: ff_id
      },
      success: function(res) {
        console.log(res)
        that.setData({
          detail: res.data,
          nodes: res.data.fw_xy
        })
      }
    })
    that.setData({
      t_id: t_id,
      ff_id: ff_id,
      fl_id: fl_id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})